home *** CD-ROM | disk | FTP | other *** search
- // Move To Trash Plug In
- //
- // © 1996 Now Software, Inc
- // written by: hac
-
- #include "Main.h"
- #include "Power.h"
-
- pascal void main(PlugInInformation *plugInInformation)
- {
- plugInInformation->version = kPlugInInformationVersionOne;
- plugInInformation->plugInType = kMoveToTrashPlugInType;
- plugInInformation->PrepareMenu = &PrepareMenu;
- plugInInformation->HandleMenuItemSelected = &HandleMenuItemSelected;
- }
-
- pascal void PrepareMenu(InstantAccessInformation *information, short asPreview)
- {
- OSErr err;
- MenuItemInformation menuItem;
-
-
- BlockMove("\pMove to Trash", menuItem.text, kMenuItemTextSize);
-
- menuItem.version = kMenuItemInformationVersionOne;
- menuItem.classification = kMiscellaneousClassification;
- menuItem.type = kTextMenuItemType;
- menuItem.id = 1;
- menuItem.enabled = true;
- menuItem.style = 0;
- menuItem.mark = 0;
- menuItem.hasSubMenu = FALSE;
- menuItem.subMenu = nil;
- menuItem.refCon = 0;
- menuItem.owningPlugInType = kMoveToTrashPlugInType;
-
- (*information->AddMenuItem)(&menuItem);
-
- error:;
-
- }
-
- pascal void CleanUpAfterMenuSelect(InstantAccessInformation *information, short asPreview)
- {
- //hmmmm....
- }
-
- pascal void HandleMenuItemSelected(InstantAccessInformation *information, MenuItemInformation *menuItem)
- {
- short selectedItemCount;
- short index;
- short foundVRefNum;
- long foundDirID;
- FSSpec fileSpec;
- FSSpec trashSpec;
- OSErr err;
- Str255 errStr;
- void* itemReference;
-
- // Find the trash
- err = FindFolder(kOnSystemDisk,kTrashFolderType,kDontCreateFolder,&foundVRefNum,&foundDirID);
- if (err != noErr) {
- goto error;
- }
-
- // specify the root as a partial pathname
- BlockMove(":", &errStr[1], 1);
- errStr[0] = 1;
-
- // make an fsspec for it
- err = FSMakeFSSpec(foundVRefNum, foundDirID, errStr, &trashSpec);
- if (err != noErr) {
- goto error;
- }
-
- // Get the number of selected items
- selectedItemCount = (*information->CountSelectedItems)();
-
- // Move each item to the trash
- for (index = 0; index < selectedItemCount; index++) {
-
- itemReference = (*information->GetNthSelectedItemReference)(index);
-
- (*information->GetSelectedItemFileSpec)(itemReference, &fileSpec);
-
- err = FSpCatMove(&fileSpec,&trashSpec);
- if (err != noErr) {
- goto error;
- }
- }
-
- error:;
- }
-